package com.jian.android.autojipai.app.helper;

import android.content.Context;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.Thread;


public class ExceptionCrashTool implements Thread.UncaughtExceptionHandler {
    private Context mContext;
    public static class ExceptionCrashToolInstance {
        private static final ExceptionCrashTool instance = new ExceptionCrashTool();

        private ExceptionCrashToolInstance() {
        }
    }

    private ExceptionCrashTool() {
    }

    public static ExceptionCrashTool getInstance() {
        return ExceptionCrashToolInstance.instance;
    }

    public void init(Context context) {
        this.mContext = context;
        Thread.currentThread().setUncaughtExceptionHandler(this);
    }

    public void uncaughtException(Thread thread, Throwable th) {
        if (this.mContext != null) {
            th.printStackTrace();
            StringWriter stringWriter = new StringWriter();
            th.printStackTrace(new PrintWriter((Writer) stringWriter, true));
            FileTool.getInstance().saveException(this.mContext, stringWriter.toString(), "app全局异常.txt");
        }
    }
}
